#include<iostream>
using namespace std;

class Solution {
public:
    int myAtoi(string str) {
        int i = 0;
        while (str[i] == ' ' || str[i] == '0')
        {
            i++;
        }
        int flag = 1;
        long num = 0;
        while (i < str.size())
        {
            if (str[i] == ' ' || str[i] == '+')
            {
                i++;
            }
            if (str[i] == '-')
            {
                flag = -1;
                i++;
            }
            if(isdigit(str[i]))
            {
                num = num * 10 + (str[i] - '0');
                i++;
            }
            if (num >= INT_MAX && flag == 1) return  INT_MAX;
            if (num > INT_MAX && flag == -1) return  INT_MIN;
        }
        return num * flag;
    }
};
int main()
{
    Solution s1;
    int ret = s1.myAtoi("4193 with words");
    cout << ret << endl;
}